package course.com.itheima.studentproject.service;

import course.com.itheima.studentproject.dao.BaseStudentDao;
import course.com.itheima.studentproject.dao.OtherStudentDao;
import course.com.itheima.studentproject.domain.Student;
import course.com.itheima.studentproject.factory.StudentDaoFactory;

public class StudentService {
    //private OtherStudentDao studentDao = new OtherStudentDao();

    private BaseStudentDao studentDao = StudentDaoFactory.getStudentDao();

    public boolean addStudent(Student student){
        return studentDao.addStudent(student);
    }

    public int isExits(String id) {
        //调用dao，拿到所有容器数据
        int index = studentDao.isExist(id);
        return index;
    }

    public Student[] findStudent() {
        Student[] arr = studentDao.findAll();
        for (int i = 0; i < arr.length; i++) {
            Student stu = arr[i];
            if(stu != null){
                return arr;
            }
        }
        return null;
    }

    public boolean updateStudent(Student stu) {
        boolean flag = studentDao.updateStudent(stu);
        return flag;
    }

    public boolean deleteStudent(int index) {
        boolean flag = studentDao.deleteStudent(index);
        return flag;
    }
}
